<template>
	<view class="alter-history-page">
		<navigation :navigationMsg="navigationMsg"></navigation>
		<view class="main">
			<view class="list">
				<view class="list-item" v-for="(item,index) in formattedTimes" :key="index">
					<view class="top">
						{{item.memo}}
					</view>
					<view class="bottom">
						<view class="left">{{item.formattedTime}}</view>
						<view class="right">
							变更金额:<span>{{item.money}}</span>,变更前:<span>{{item.after}}</span>变更后:<span>{{item.before}}</span>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		http
	} from '@/api/index.js'
	import navigation from '../../../components/navigation.vue';
	export default {
		data() {
			return {
				navigationMsg: {
					title: "资金流水"
				},
				moneyList: []
			}
		},
		onShow() {
			this.getList()
		},
		components: {
			navigation
		},
		computed: {
			//转换时间
			formattedTimes() {
				return this.moneyList.map((item, index) => {
					const date = new Date(item.create_time * 1000)
					const year = date.getFullYear();
					const month = (date.getMonth() + 1).toString().padStart(2, '0');
					const day = date.getDate().toString().padStart(2, '0');
					const hours = date.getHours().toString().padStart(2, '0');
					const minutes = date.getMinutes().toString().padStart(2, '0');
					const seconds = date.getSeconds().toString().padStart(2, '0');
					const formattedTime = `${year}-${month}-${day}`;
					return {
						...item,
						formattedTime
					};
				})
			},
		},
		methods: {
			getList() {
				http.post('/api/user/moneyLog').then(res => {
					console.log(res, 'res');
					this.moneyList = res.data
				}).catch(err => {
					console.log(err, 'err');
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	:root {
		--bg-color: ;
		--text-color: ;
	}

	.alter-history-page {
		width: 100%;
		height: 100vh;
		background-color: var(--bg-color);

		.main {
			width: 100%;
			height: calc(100% - 100rpx);
			overflow: hidden;

			.list {
				width: 90%;
				height: calc(100% - 100rpx);
				margin: auto;
				margin-top: 30rpx;
				overflow-y: scroll;
				border-radius: 30rpx;
				border: 1px solid #ccc;

				.list-item {
					width: 100%;
					height: 150rpx;
					background-color: var(--bg-color);
					justify-content: space-between;
					color: var(--text-color);

					.top {
						width: 95%;
						height: 60rpx;
						font-size: 24rpx;
						margin: auto;
						padding-top: 10rpx;
						font-weight: bold;
					}

					.bottom {
						width: 95%;
						height: calc(100% - 60rpx);
						margin: auto;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.left {
							min-width: 140rpx;
							font-size: 22rpx;
							padding-left: 10rpx;
							color: #8c8c8c;
						}

						.right {
							font-size: 22rpx;
							text-align: right;

							>span {
								font-weight: bold;
							}
						}
					}
				}

				.list-item:not(:last-child) {
					border-bottom: 1px solid #e5e5e5;
				}

				.list-item:last-child {
					border-radius: 0px 0px 30rpx 30rpx;
				}
			}
		}
	}
</style>